<?php


namespace app\api\controller\v1;

use app\api\model\User as UserModel;
use app\api\service\Token as TokenService;
use app\api\vaildate\AdressNew;
use app\lib\exception\SuccessMessage;

class Address
{
    public function createOrUpdateAddress()
    {
        $vaildate = new AdressNew();
        $vaildate->goCheck();
        $uid = TokenService::getCurrentUid();
        $dataArray = $vaildate->getDataByRule(input('post.'));
        $user = UserModel::get($uid);
        if (empty($user->address)) {
            //新增记录带括号（）
            $user->address()->save($dataArray);
        } else {
            //更新记录不带括号
            $user->address->save($dataArray);
        }
        return new SuccessMessage();
    }
}